package linkedlist.pro;

import linkedlist.ListNode;

/**
 * @Classname : RemoveDuplicatesFromSortedList
 * @Description :
 * <a href="https://leetcode.cn/problems/remove-duplicates-from-sorted-list/">83. 删除排序链表中的重复元素</a>
 * @Author : chentianyu
 * @Date 2022/12/26 21:37
 */


public class RemoveDuplicatesFromSortedList {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head;
        while (cur != null && cur.next != null) {
            ListNode next = cur.next;
            if (cur.val == next.val) {
                cur.next = next.next;
                next.next = null;
            } else {
                cur = cur.next;
            }
        }
        return head;
    }
}
